$(function () {
	$(".authorTent-follow .authorTent-followA").click(function() {
		var that = $(this);
		var authorid = that.data('authorid');
		var userid = $("#userid").data("userid");
		if(userid != ''){
			 if(that.hasClass('authorTent-iActive') || that.hasClass('authorTent-iMutual')){
				 layer.open({
				        content: '是否取消关注?',
				        btn: ['确定', '取消'],
				        yes: function (index) {
				        	$.ajax({ 
								 url: '/operate/'+ userid + '/cancel/' + authorid, 
								 type: "POST",
						         data: {},
						         dataType: "json",//请求数据类型
								 success: function(data){
									 layer.close(index);
									 if(data.code == 0){
								        that.removeClass("authorTent-iActive");
								        that.removeClass("authorTent-iMutual");
								        that.text("+关注")
								        var num = Number($('#F' + authorid).text());
								        $('#F' + authorid).text(num-1);
									 }else{
										 layer.msg(data.msg);
									 }
								 },
								 error : function() {
									 layer.close(index);
									 layer.msg("取消关注异常");
								 }
							 })	
				        },
				        no: function () {

				        }
				    });
			}else{
				$.ajax({ 
					 url: '/operate/'+ userid + '/follow/' + authorid, 
					 type: "POST",
			         data: {},
			         dataType: "json",//请求数据类型
					 success: function(data){
						 var result = data.data;
						 if(data.code == 0){
							if(result == 1){
								that.addClass("authorTent-iActive");
						        that.text("✓已关注")
							 }else if(result == 2){
								 that.addClass("authorTent-iMutual");
							     that.text("⇋互为关注")
							 }
							 var num = Number($('#F' + authorid).text());
						     $('#F' + authorid).text(num+1);
						 }else{
							 layer.msg(data.msg);
						 }
					 },
					 error : function() {
						 layer.msg("关注失败");
					 }
				 })
			}
			
		}else{
			window.location.href = "/signup"
		}
	});
	
});

//推荐作者
function follow(authorid,thit){
	var that = $(thit);
	var type = that.data("id");
	var userid = $("#userid").data("userid");
	if(userid != ''){
		 if(type == '1' || type == '2'){
			 layer.open({
			        content: '是否取消关注?',
			        btn: ['确定', '取消'],
			        yes: function (index) {
			        	$.ajax({ 
							 url: '/operate/'+ userid + '/cancel/' + authorid, 
							 type: "POST",
					         data: {},
					         dataType: "json",//请求数据类型
							 success: function(data){
								 layer.close(index);
								 if(data.code == 0){
							        that.removeClass("frAuthor-cLi-frS2");
							        that.text("+关注")
							        that.data('id','0');
								 }else{
									 layer.msg(data.msg);
								 }
							 },
							 error : function() {
								 layer.close(index);
								 layer.msg("取消关注异常");
							 }
						 })	
			        },
			        no: function () {

			        }
			    });
		}else{
			$.ajax({ 
				 url: '/operate/'+ userid + '/follow/' + authorid, 
				 type: "POST",
		         data: {},
		         dataType: "json",//请求数据类型
				 success: function(data){
					 var result = data.data;
					 if(data.code == 0){
						if(result == 1){
							that.addClass("frAuthor-cLi-frS2");
					        that.text("✓已关注")
					        that.data('id','1');
						 }else if(result == 2){
						     that.text("⇋互为关注")
						     that.data('id','2');
						 }
					 }else{
						 layer.msg(data.msg);
					 }
				 },
				 error : function() {
					 layer.msg("关注失败");
				 }
			 })
		}
		
	}else{
		window.location.href = "/signup"
	}
}

//关注与取消
function followfans(userid,authorid,thzs){
	 var that = $(thzs);
     if(that.hasClass('information-noSwitch') || that.hasClass('information-iMutual')){
    	 layer.open({
 	        content: '是否取消关注?',
 	        btn: ['确定', '取消'],
 	        yes: function (index) {
 	        	$.ajax({ 
 	  			 url: '/operate/'+ userid + '/cancel/' + authorid, 
 	  			 type: "POST",
 	  	         data: {},
 	  	         dataType: "json",//请求数据类型
 	  			 success: function(data){
 	  				 layer.close(index);
 	  				 if(data.code == 0){
 	  					 that.removeClass("information-noSwitch");
 	  					 that.removeClass("information-iMutual");
 	  				     that.text("+关注")
 	  				    //用户粉丝减1	
				        var nums = Number($('#' +  + authorid + 'fans').text());
				        if(nums-1 >= 0){
				        	$('#' +  + authorid + 'fans').text(nums-1);
				        }else{
				        	$('#' +  + authorid + 'fans').text(nums-1);
				        }
 	  				 }else{
 	  					 layer.msg(data.msg,{icon:7});
 	  				 }
 	  			 },
 	  			 error : function() {
 	  				layer.close(index);
 	  				layer.msg("取消关注异常",{icon:7});
 	  			 }
 	  		 })
 	        },
 	        no: function () {

 	        }
 	    });
     }else{
    	 $.ajax({ 
    		 url: '/operate/'+ userid + '/follow/' + authorid, 
    		 type: "POST",
            data: {},
            dataType: "json",//请求数据类型
    		 success: function(data){
    			 var result = data.data;
    			 if(data.code == 0){
    				if(result == 1){
    					that.addClass("information-noSwitch");
    			        that.text("✓已关注")
    				 }else if(result == 2){
    					that.addClass("information-iMutual");
    				    that.text("⇋互为关注")
    				 }
    				//用户粉丝加1	
			        var nums = Number($('#' +  + authorid + 'fans').text());
			        $('#' +  + authorid + 'fans').text(nums+1);
    			 }else{
    				 layer.msg(data.msg);
    			 }
    		 },
    		 error : function() {
    			 layer.msg("关注失败");
    		 }
    	 })
     }
}